<?php

namespace App\Admin\Controllers\cms;

use App\Models\Article;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;

class ArticleController extends AdminController
{

    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '防伪溯源';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Article);

        $grid->id('Id');
        $grid->title('标题');
        $grid->column('material', __('材料追溯'))->display(function(){
            return '查看';
        })->modal('材料追溯', function ($model) {
            return $model->material;
        });
        $grid->column('inspection', __('检验入库'))->display(function(){
            return '查看';
        })->modal('检验入库', function ($model) {
            return $model->inspection;
        });
        $grid->column('processing', __('生产加工'))->display(function(){
            return '查看';
        })->modal('生产加工', function ($model) {
            return $model->processing;
        });
        $grid->column('production', __('产品检验'))->display(function(){
            return '查看';
        })->modal('产品检验', function ($model) {
            return $model->production;
        });
        $grid->created_at('创建时间');
        $grid->updated_at('修改时间');
        $grid->actions(function ($actions) {
            // 去掉查看
            $actions->disableView();
        });
        $grid->filter(function($filter){
            // 去掉默认的id过滤器
            $filter->disableIdFilter();
            $filter->column(1/2, function ($filter) {
                $filter->like('title', '标题');
            });
            $filter->column(1/2, function ($filter) {
                $filter->equal('code', '效验码');

            });
            $filter->column(1/2, function ($filter) {
                $filter->between('created_at', '创建时间')->datetime();

            });

        });
        $grid->disableFilter();
        $grid->disableExport();
        $grid->disableColumnSelector();
        return $grid;
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Article);
        $form->text('title', '标题')->rules('required');
        $form->textarea('material', '材料追溯');
        $form->textarea('inspection', '检验入库');
        $form->textarea('processing', '生产加工');
        $form->textarea('production', '产品检验');
        $form->tools(function (Form\Tools $tools) {
            $tools->disableDelete();
            $tools->disableView();
        });
        $form->footer(function ($footer) {
            $footer->disableReset();
            $footer->disableViewCheck();
            $footer->disableEditingCheck();
            $footer->disableCreatingCheck();
        });
        return $form;
    }

}
